package com.strange.mdl.module.mdl.dal.mysql.user;

import java.util.*;

import com.strange.mdl.framework.common.pojo.PageResult;
import com.strange.mdl.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.strange.mdl.framework.mybatis.core.mapper.BaseMapperX;
import com.strange.mdl.module.mdl.dal.dataobject.user.MdlUserDO;
import org.apache.ibatis.annotations.Mapper;
import com.strange.mdl.module.mdl.controller.admin.user.vo.*;

/**
 * 用户 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface MdlUserMapper extends BaseMapperX<MdlUserDO> {

    default PageResult<MdlUserDO> selectPage(MdlUserPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MdlUserDO>()
                .eqIfPresent(MdlUserDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(MdlUserDO::getUnionid, reqVO.getUnionid())
                .eqIfPresent(MdlUserDO::getSessionKey, reqVO.getSessionKey())
                .likeIfPresent(MdlUserDO::getUsername, reqVO.getUsername())
                .likeIfPresent(MdlUserDO::getDharmaName, reqVO.getDharmaName())
                .eqIfPresent(MdlUserDO::getPassword, reqVO.getPassword())
                .eqIfPresent(MdlUserDO::getPhone, reqVO.getPhone())
                .eqIfPresent(MdlUserDO::getIsActive, reqVO.getIsActive())
                .eqIfPresent(MdlUserDO::getIsMember, reqVO.getIsMember())
                .eqIfPresent(MdlUserDO::getMemberLevel, reqVO.getMemberLevel())
                .eqIfPresent(MdlUserDO::getBirthDate, reqVO.getBirthDate())
                .eqIfPresent(MdlUserDO::getProvince, reqVO.getProvince())
                .eqIfPresent(MdlUserDO::getCity, reqVO.getCity())
                .eqIfPresent(MdlUserDO::getDistrict, reqVO.getDistrict())
                .eqIfPresent(MdlUserDO::getDetailAddress, reqVO.getDetailAddress())
                .eqIfPresent(MdlUserDO::getSex, reqVO.getSex())
                .eqIfPresent(MdlUserDO::getAvatarUrl, reqVO.getAvatarUrl())
                .eqIfPresent(MdlUserDO::getTotalMerit, reqVO.getTotalMerit())
                .orderByDesc(MdlUserDO::getId));
    }

    default MdlUserDO selectByMobile(String mobile) {
        return selectOne(MdlUserDO::getPhone, mobile);
    }
}